# coding=utf-8
# @Time: 2023/2/5 2:58
# @Author: zyg
# email: zhaoyiguang@lecent.cn

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager


class DriverConfig:
    def driver_config(self):
        """
        浏览器驱动
        :return:
        """
        options = webdriver.ChromeOptions()
        # 设置窗口大小，设置为1920*1080
        options.add_argument("window-size=1920,1080")
        # 去除"Chrome正受到自动测试软件的控制"提示信息
        options.add_experimental_option(
            "excludeSwitches", ["enable-automation"])
        # 解决selenium无法访问https的问题
        options.add_argument("--ignore-certificate-errors")
        # 允许忽略localhost上的TLS/SSL错误
        options.add_argument("--allow-insecure-localhost")
        # 设置为无痕模式
        options.add_argument("--incognito")
        # 设置为无头模式
        # options.add_argument("--headless")
        # 解决卡顿
        options.add_argument("--disable-gpu")  # 禁用GPU，页面加速
        options.add_argument("--no-sandbox")  # 禁用sandbox，页面加速
        options.add_argument("--disable-dev-shm-usage")

        # driver_path = get_project_path() + sep(["driver_file", "chromedriver"], add_sep_before=True)
        # driver = webdriver.Chrome(executable_path=driver_path, options=options)

        # driver = webdriver.Chrome()
        # driver.maximize_window()

        driver = webdriver.Chrome(
            ChromeDriverManager(
                # url="http://npm.taobao.org/mirrors/chromedriver",
                # latest_release_url="http://npm.taobao.org/mirrors/chromedriver/LATEST_RELEASE",
                # cache_valid_range=365).install(),
                url="https://registry.npmmirror.com/-/binary/chromedriver",
                latest_release_url="https://registry.npmmirror.com/-/binary/chromedriver/LATEST_RELEASE",
                cache_valid_range=365).install(),
            options=options)
        # 删除所有cookie
        driver.delete_all_cookies()
        return driver


if __name__ == '__main__':
    pass
